#! /usr/bin/perl
use strict;
use warnings;

###### 
# NGSbox - bioinformatics analysis tools for next generation sequencing data
#
# Copyright 2007-2011 Stephan Ossowski, Korbinian Schneeberger
# 
# NGSbox is free software: you can redistribute it and/or modify it under the 
# terms of the GNU General Public License as published by the Free Software 
# Foundation, either version 3 of the License, or any later version.
#
# NGSbox is distributed in the hope that it will be useful, but WITHOUT ANY 
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# Please find the GNU General Public License at <http://www.gnu.org/licenses/>.
#
#  -------------------------------------------------------------------------
#
#  Module: Parser::FASTA::check_4_identical_reads.pl
#  Purpose:
#  In:
#  Out:
#


open FILE, shift;

my %SEQ= ();
my $seq = "";
my $id = "";


### Check fasta file for duplicate sequences
while (<FILE>) {

	chomp();

	if (substr($_, 0, 1) eq ">") {
		my @a = split " ";
		if ($seq ne "") {
			if (defined($SEQ{$seq})) {
				print "Duplicates: ", $SEQ{$seq}, " $id\ņ";
			}
			$SEQ{$seq} .= $id." ";
		}
		$id = substr($a[0], 1, length($a[0])-1);
		$seq = "";
	}
	else {
		$seq.=$_;
	}
}

### Last entry
if ($seq ne "") {
	if (defined($SEQ{$seq})) {
		print "Duplicates: ", $SEQ{$seq}, " $id\ņ";
	}
	$SEQ{$seq} .= $id." ";
}
